package org.mtmi.midi;

import org.mtmi.tuio.listeners.TUIOTapEvent;
import org.mtmi.ui.M;
import org.mtmi.ui.controls.Button;
import org.mtmi.ui.scenes.Scene;

import rwmidi.MidiOutput;

public class SendMidiNoteButton extends Button  {

	int midiChannel;
	int pitch;
	int velocity;
	MidiOutput midiOutput;
	
	public SendMidiNoteButton(Scene scene) {
		super(scene, M.SCENE_CONTROL);
	}
	
	public SendMidiNoteButton(Scene scene, int midiChannel,int pitch, int velocity) {
		super(scene, M.SCENE_CONTROL);
		this.midiChannel = midiChannel;
		this.pitch = pitch;
		this.velocity = velocity;
	}
	
	public MidiOutput getMidiOutput() {
		return midiOutput;
	}
	
	public void setMidiOutput(MidiOutput midiOutput) {
		this.midiOutput = midiOutput;
	}
	
	public int getMidiChannel() {
		return midiChannel;
	}
	
	public void setMidiChannel(int midiChannel) {
		this.midiChannel = midiChannel;
	}
	
	
	public int getPitch() {
		return pitch;
	}
	
	public void setPitch(int pitch) {
		this.pitch = pitch;
	}
	
	
	public int getVelocity() {
		return velocity;
	}
	
	public void setVelociry(int velocity) {
		this.velocity = velocity;
	}
	
	
	private void sendNoteOffMessage() {
		midiOutput.sendNoteOff(midiChannel, pitch, velocity);
	}

	private void sendNoteOnMessage() {
		midiOutput.sendNoteOn(midiChannel, pitch, velocity);		
	}
	
	@Override
	public void tapDown(TUIOTapEvent event) {
		//Debug info
		System.out.println("Note on");
		super.tapDown(event);
		sendNoteOnMessage();
	}
	
	@Override
	public void tapUp(TUIOTapEvent event) {
		//Debug info
		System.out.println("Note off");
		super.tapUp(event);
		sendNoteOffMessage();
	}

}
